﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using Borland.Studio.ToolsAPI;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.Client;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.IO;

namespace SimpleDelphiExpert
{
    public class SimpleExpert: IOTAWizard, IOTAMenuWizard
    {
        private const string expertIDString = "SimpleDelphiExpert";
        private const string expertName = "Simple Delphi Expert on C#";

        private static int WizardId;
        private static int FileHistoryProviderId;

        public static T GetService<T>()
        {
            return (T)BorlandIDE.GetService(typeof(T));
        }

        public static void IDERegister()
        {
            GetService<IOTASplashScreenService>().AddPluginBitmap(expertName, System.IntPtr.Zero, false, "", "");
            
            IOTAWizardService service = GetService<IOTAWizardService>();
            WizardId = service.AddWizard(new SimpleExpert());
        
            FileHistoryProviderId = GetService<IOTAFileHistoryManager>().RegisterHistoryProvider(new TfsFileHistoryProvider());
        }

        public bool Checked
        {
            get { return false; }
        }

        public bool Enabled
        {
            get { return true; }
        }

        public string MenuText
        {
            get { return "Simple Menu Text"; }
        }

        public void Destroyed()
        {
            GetService<IOTAFileHistoryManager>().UnregisterHistoryProvider(FileHistoryProviderId);

            IOTAWizardService service = GetService<IOTAWizardService>();
            service.RemoveWizard(WizardId);
        }

        public void Execute()
        {
            global::System.Windows.Forms.MessageBox.Show("Execute");
        }

        public string IDString
        {
            get { return expertIDString; }
        }

        public string Name
        {
            get { return expertName; }
        }
    }
}
